version 14.2
set more off

***************************************************************************************************************************
* THIS ROUTINE GENERATES FIGURES VI OF WASEEM (2020) ROLE OF WITHHOLDING ...
***************************************************************************************************************************

/* ALL MANUFACTURERS */
*----------------------

use					"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                if business_sts=="1" 
keep				if fy>1995 & fy<=2001
g					ind=real(substr(item_cd,1,4))
drop				if ind<1600
drop				if ind>=2500 & ind<2800
duplicates			drop 
keep				taxperiod input output regno tau business_sts tot_sale item_cd fy
bys					regno taxperiod:egen inputag=sum(input)
bys					regno taxperiod:egen outputag=sum(output)
duplicates			drop regno taxperiod, force
replace				inputag=inputag/tau
replace				outputag=outputag/tau
g					npurchag=-inputag
egen				va=rowtotal(outputag npurchag)
g					one=1
keep				if va>-100000 & va<=100000
drop				if va==0
g					vabin=ceil(va/5000)
replace				vabin=vabin*5000
bys					vabin fy:egen freq=sum(one)
bys					vabin fy:gen index=_n
sort 				fy vabin
by					fy:g rsum_t=sum(one)
by					fy:egen tsum=sum(one)
bys					vabin fy:egen rsum=max(rsum_t)
g					cdf=rsum/tsum
forvalues			y=1998/1999 {
#d					;
twoway  			(connected  freq vabin if fy==`y' & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(S)),
					xtitle("Reported Sales Minus Inputs in PKRs") xtitle(, alignment(top))
					xlabel(-100000(50000)100000) xscale(titlegap(*10))
					yscale(r(0))  yscale(titlegap(*10)) ytitle("Number of Firms") 
					xline(0, lpatter(dash) lcolor(green)) ylabel(0(2000)8000)
					legend(region(style(none)) label(1 "Manufacturers") label(2 "Importers"))
					graphregion(fcolor(white) style(none) color(white) margin(0 4 0 2)) bgcolor(white);
graph 				export "$project_output\Bunching_Zero_Liability_Manuf_`y'.eps", replace;
#d					cr
}
#d					;
twoway  			(connected  freq vabin if fy==1998 & index==1,sort lpattern(shortdash) lcolor(erose) mcolor(erose) msymbol(S))
					(connected  freq vabin if fy==1999 & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(O)),
					xtitle("Reported Sales Minus Inputs in PKRs") xtitle(, alignment(top))
					xlabel(-100000(50000)100000) xscale(titlegap(*10))
					yscale(r(0))  yscale(titlegap(*10)) ytitle("Number of Firms") 
					xline(0, lpatter(dash) lcolor(green)) ylabel(0(2000)8000)
					legend(region(style(none)) label(1 "1998") label(2 "1999"))
					graphregion(fcolor(white) style(none) color(white) margin(0 4 0 2)) bgcolor(white);
graph 				export "$project_output\Bunching_Zero_Liability_Manuf_98v99.eps", replace;
#d					cr

#d					;
twoway  			(line  cdf vabin if fy==1998 & index==1,sort lpattern(shortdash) lcolor(erose) mcolor(erose) msymbol(S))
					(line  cdf vabin if fy==1999 & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(O)),
					xtitle("Reported Sales Minus Inputs in PKRs") xtitle(, alignment(top))
					xlabel(-100000(50000)100000) xscale(titlegap(*10))
					yscale(r(0))  yscale(titlegap(*10)) ytitle(Pr (X < x), alignment(bottom))
					xline(0, lpatter(dash) lcolor(green)) ylabel(0(0.2)1)
					legend(region(style(none)) label(1 "1998") label(2 "1999"))
					graphregion(fcolor(white) style(none) color(white) margin(0 4 0 2)) bgcolor(white);
graph 				export "$project_output\Bunching_Zero_Liability_Manuf_CDF_98v99.eps", replace;
#d					cr